home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / utility.lha / utility / statcount.H < prev    next >
C/C++ Source or Header  |  1993-08-08  |  2KB  |  64 lines

  1. // StatCount is a class for simple statistics gathering in C++ programs.
  2. // Integer values are counted in equal-sized bins during the lifetime
  3. // of the StatCount object.  The values of the bins are printed when the
  4. // object is destroyed.
  5. //
  6. // Statcount uses the stdio library and does not depend on intialization
  7. // of C++ i/o streams.  It can therefore be used in constructors and
  8. // destructors of static objects.
  9. //
  10. // .SS Example
  11. // .nf
  12. // void f(int x) {
  13. //    static StatCount cnt("Arguments to f", 0, 100, 10);
  14. //    cnt(x);
  15. //    ....
  16. // }
  17. //
  18. // .SS Author
  19. // Dag Bruck
  20. //
  21. // $Id: statcount.H,v 1.1 91/09/06 12:01:49 dag Exp $
  22.  
  23.  
  24. #ifndef STATCOUNT_H
  25. #define STATCOUNT_H
  26.  
  27.  
  28. class StatCount {
  29. public:
  30.   StatCount(const char* t, int min, int max, unsigned res);
  31.   // Creates a statistics counter with given title, range and resolution.
  32.   // The range of the counters is [min, max[.
  33.   // The title is copied internally.
  34.  
  35.   void operator () (int x);
  36.   // Registers the value of `x' in the appropriate counter. A value outside
  37.   // the range given to the constructor will be registered in the first or
  38.   // last counter.
  39.  
  40.   void Dump() const;
  41.   // Prints the contents of the counters on standard error output,
  42.   // preceded by the title given to the constructor.
  43.  
  44.   ~StatCount();
  45.   // Calls Dump() and frees allocated storage.
  46.  
  47. private:
  48.   char* title;
  49.   // Title of print-out.
  50.   
  51.   int min;
  52.   unsigned res;
  53.   // Minimum value and resolution.
  54.   
  55.   unsigned n;
  56.   // Number of counters.
  57.   
  58.   unsigned* v;
  59.   // Array of counters.
  60. };
  61.  
  62.  
  63. #endif
  64.